//
//  PersonalHomePageViewController.m
//  SHHCPhone
//
//  Created by Sheng long on 14-7-14.
//  Copyright (c) 2014年 sheng long. All rights reserved.
//

#import "PersonalHomePageViewController.h"
#import "PersonalHomePageView.h"

@interface PersonalHomePageViewController ()<PerfectContentViewDelegate>
{
    PersonalHomePageView *phpView;
}
@end

@implementation PersonalHomePageViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    [navigationBarView setTitle:@"个人主页"];
    [navigationBarView setNormalLeftButton];
    
    phpView = [[PersonalHomePageView alloc] initWithFrame:CGRectMake(0, NAVIGATIONBAR_HEIGHT, CURRENT_CONTENT_WIDTH, CURRENT_CONTENT_HEIGHT-NAVIGATIONBAR_HEIGHT)];
    [phpView setDelegate:self];
    [phpView setUIVC:self];
    [self.view addSubview:phpView];
}

//完成设置
-(void)done:(NSDictionary *)dic
{
    [LoadingFrameView showLoadingview];
    [dic setValue:IOS_UPDATE forKeyPath:IOS_METHOD_NAME];
    [dic setValue:APP_USER_MSG.id forKey:@"id"];
    NSDictionary *d = [phpView addMsg:dic];
    [self superASIStartAsynchronous:[NetUtls httpPost:self withValue:d tag:IOS_UPDATE_TAG need:YES]];
}

#pragma mark - ASIHTTPRequestDelegate
-(void)requestFinished:(ASIHTTPRequest *)request
{
    
}

-(void)requestFailed:(ASIHTTPRequest *)request
{
    CLog(@"%@",[request responseString]);
    [LoadingFrameView autoDisappearBlockingview:@"修改个人主页失败"];
}

-(void)getASIRecordSucceed:(ASIHTTPRequest *)request data:(NSDictionary *)dic
{
    CLog(@"获取数据成功");
    //保存用户信息在本地，下次自动登录
    NSMutableDictionary *d = [NSMutableDictionary dictionaryWithDictionary:dic];
    [d setValue:APP_USER_MSG.password forKey:@"password"];
    [APP_USERDEFAULTS setValue:[d JSONString] forKey:APP_LOGIN_SUCESS_SVAE_MSG];
    
    UserMsg *info = [[UserMsg alloc] init:d];
    APP_USER_MSG = info;
    [LoadingFrameView autoDisappearBlockingview:@"修改成功"];
    [self.navigationController popViewControllerAnimated:YES];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:APP_UPDATE_USER_MSG object:nil];
}

-(void)getASIRecordFailed:(ASIHTTPRequest *)request data:(NSString *)failed
{
    [LoadingFrameView autoDisappearBlockingview:failed];
}

@end
